<?php

use \think\facade\Route;

/**
 * 添加RESTFul路由
 */
Route::rest([
    'saves' => ['POST', '', 'saves'],
    'updates' => ['PUT', '/:id', 'updates'],
    'deletes' => ['DELETE', '/:ids', 'deletes'],
    'saveList' => ['POST', '/list', 'saveList'],
]);

Route::group('apis', function () {
    Route::group('v1', function () { //第一版接口
        //************************资源接口************************
        //Rooms模块
        Route::resource('rooms', 'api/v1.Rooms', [], [
            'id' => '\w{3,10}',
            'ids' => '\w{3,10}(?:,\w{3,10})*',
        ])->only(['index', 'save', 'update']);
        Route::get('room_names', 'api/v1.Rooms/getRoomNames');
        Route::get('building_names', 'api/v1.Rooms/getBuildingNames');
        Route::get('busy_room', 'api/v1.Rooms/getBusyRoom');

        //Terms模块
        Route::resource('terms', 'api/v1.Terms', [], [
            'id' => '\d+',
            'ids' => '\d+(?:,\d+)*',
        ]);
        Route::get('cur_term_id', 'api/v1.Terms/getDefaultTermID');
        Route::post('cur_term_id', 'api/v1.Terms/setDefaultTermID');
        Route::get('start_date', 'api/v1.Terms/getStartDate');

        //Assistants模块
        Route::resource('assistants', 'api/v1.Assistants', [], [
            'id' => '\d+',
            'ids' => '\d+(?:,\d+)*',
        ]);
        Route::post('assistant_unbind', 'api/v1.Assistants/unbind');

        //CoursesAssistant模块
        Route::resource('courses_assistant', 'api/v1.CoursesAssistant', [], [
            'id' => '\d+',
            'ids' => '\d+(?:,\d+)+',
        ]);

        ///DutyArranges模块
        Route::resource('duty_arranges', 'api/v1.DutyArranges')->only(['index', 'saveList']);
        Route::get('duty_assistants', 'api/v1.DutyArranges/getDutyAssistant');

        //DutyRecords模块
        Route::resource('duty_records', 'api/v1.DutyRecords')->only(['index']);

        //CourseAdjusts模块
        Route::resource('course_adjusts', 'api/v1.CourseAdjusts',[],[
            'id'=>'\d{4}-\d{2}-\d{2}',
        'ids'=>'\d{4}-\d{2}-\d{2}(?:,\d{4}-\d{2}-\d{2})+'
        ])->only(['index', 'update', 'save','delete','deletes']);
        Route::get('course_adjust_map', 'api/v1.CourseAdjusts/getMap');

        //CourseRoom模块
        Route::resource('courses_room', 'api/v1.CoursesRoom');
        Route::get('teacher_names', 'api/v1.CoursesRoom/getTeacherNames');
        Route::get('class_names', 'api/v1.CoursesRoom/getClassNames');
        Route::get('schedule_advise', 'api/v1.CoursesRoom/scheduleAdvise');     //排课建议接口

        //Buildings模块
        Route::resource('buildings', 'api/v1.Buildings')->only(['index', 'delete', 'deletes']);
        Route::post('bind_building', 'api/v1.Buildings/registerKey');
        Route::post('unbind_building', 'api/v1.Buildings/unregisterKey');


        //Users模块
        Route::resource('users','api/v1.Users');
        Route::post('reset_password','api/v1.Users/ResetPassword');     //超级管理员专用的重置密码接口
        

        //************************基础接口************************
        Route::post('login', 'api/v1.Base/login');
        Route::post('logout', 'api/v1.Base/logout');
        Route::post('change_password','api/v1.Users/changePassword');
        Route::get('timestamp', 'api/v1.Base/getTime');
        Route::get('permission', 'api/v1.Base/getPermissionLevel');

        //*************************签到接口***********************
        Route::post('sign_in', 'api/v1.DutySignInOut/signInSelf');
        Route::post('sign_out', 'api/v1.DutySignInOut/signOutSelf');
        Route::post('check_bkey', 'api/v1.DutySignInOut/checkBKeyValidate');
        
    });
    Route::miss(function () {
        return json_response([], STATUS_NOT_FOUND, '未定义的接口');
    });
})->allowCrossDomain();
